<?php

class Group extends DirModel
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ut_calcrow_group';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ut_group_name', 'required'),
			array('ut_group_name', 'length', 'max'=>255),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'calcrow' => array(self::HAS_MANY, 'Calcrow', 'ut_paper_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ut_group_id' => 'Id',
			'ut_group_name' => 'Расчетная группа',
		);
	}
	
	public function exp_area($edition)
	{
		$edition=max($edition,$this->min_edition);
		$paperExpense = PaperExpense::model('PaperExpense')->find(array('condition'=>'ut_exp_edition<='.$edition,'order'=>'ut_exp_edition desc'));
		return $paperExpense->ut_exp_count*$paperExpense->base_format->ut_format_width*$paperExpense->base_format->ut_format_length;
	}

}